package com.csun.cmny.provider.task;

import com.csun.cmny.provider.model.domain.OmcAnalysis;
import com.csun.cmny.provider.pojo.SexCountVo;
import com.csun.cmny.provider.service.OldmanCheckInService;
import com.csun.cmny.provider.service.OmcAnalysisService;
import com.csun.cmny.provider.vo.CheckinUserInfoVo;
import com.csun.cmny.util.PublicUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lijun
 * @description:
 * @date 2019/11/12 20:52
 */
@Slf4j
@Component
//public class AnalysisQuartz extends QuartzJobBean {
public class AnalysisQuartz {
    @Resource
    OmcAnalysisService omcAnalysisService;
    @Resource
    OldmanCheckInService oldmanCheckInService;
//    @Override
//    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
//        JobDataMap jobMap = jobExecutionContext.getJobDetail().getJobDataMap();
//        Long groupId = jobMap.getLong("groupId");
//        if (null != groupId && groupId > 0) {
//            Calendar now = Calendar.getInstance();
//            int month = now.get(Calendar.MONTH)+1;
//            int year = now.get(Calendar.YEAR);
//            Map map = new HashMap();
//            map.put("month",month);
//            map.put("year",year);
//            map.put("homeId",groupId);
//            SexCountVo vo = oldmanCheckInService.getOldmanNalysis(map);
//            OmcAnalysis record = new OmcAnalysis();
//            Date date = new Date();
//            record.setGroupId(groupId);
//            record.setOnCount(vo.getRuyuan());
//            record.setHomeCount(vo.getJujia());
//            record.setSaveTime(date);
//            omcAnalysisService.save(record);
//        }
//    }

    public void calc() {

        List<CheckinUserInfoVo> list = oldmanCheckInService.selectGroupId();
        if (PublicUtil.isEmpty(list)) {
            return ;
        }

        for (CheckinUserInfoVo cv : list) {

            Long groupId = cv.getHomeId().longValue();
            Map map = new HashMap();
            map.put("homeId",groupId);
            SexCountVo vo = oldmanCheckInService.getOldmanNalysis(map);
            OmcAnalysis record = new OmcAnalysis();
            Date date = new Date();
            record.setGroupId(groupId);
            record.setOnCount(vo.getRuyuan());
            record.setHomeCount(vo.getJujia());
            record.setSaveTime(date);

            omcAnalysisService.save(record);
        }
    }

}
